
# 闭包示例
import time
import random

def my_power():
	b = 0.01
	print("my_power")
	def calc_power(x):
		print("calc_power:x=", x)
		print("calc_power:b=", b)
		return x ** 2 + b
	return calc_power

f1 = my_power()  # f指向内部函数line()
f2 = my_power()  # f指向内部函数line()
print(f1(3))
#print(f2(4))
print("---------------------------")


def outer(func):
	def inner():
		start_time = time.time()
		func()
		end_time = time.time()
		print("运行时间:", end_time - start_time)
	return inner

def index():
	time.sleep(random.randrange(1,3))
	print("Welcom to index page")
	return

f = outer(index)
f()
